package fr.mairie.parc.control.materiel;

import java.util.ArrayList;
import java.util.List;

import org.apache.click.control.FieldSet;
import org.apache.click.control.Form;
import org.apache.click.control.Option;
import org.apache.click.control.Select;
import org.apache.click.dataprovider.DataProvider;
import org.apache.click.extras.control.IntegerField;

import fr.mairie.parc.domain.Materiel;

public class MaterielValidationFields {
	
	protected FieldSet fieldSet;
	protected MaterielFields materielfield;
	protected IntegerField numParc;
	private Select etat = new Select("etat", "Etat");
	

	@SuppressWarnings({ "rawtypes", "serial" })
	public MaterielValidationFields () {
		fieldSet = new FieldSet("validation", "Valider matériel");

		numParc = new IntegerField("numParc", "Numéro de parc");
		
		fieldSet.add(numParc);
		
		etat.setDefaultOption(new Option ("etat","Choisir l'état"));
		etat.setDataProvider(new DataProvider() {
			
			@SuppressWarnings("unchecked")
			public List getData() {
                List optionList = new ArrayList();
                optionList.add(new Option("disponible", "Disponible"));
                optionList.add(new Option("nonDisponible", "Non disponible"));
                return optionList;
            }
		});
		fieldSet.add(etat);
	}

	public FieldSet getFieldSet() {
		return fieldSet;
	}

	public void addTo(Form form) {
		form.add(fieldSet);
	}

	public void addTo(Form form, boolean readonly) {
		form.add(fieldSet);
		fieldSet.setReadonly(readonly);
	}

	public void setReadonly(boolean p) {
		fieldSet.setReadonly(p);
	}

	 public void getFieldValues(Materiel in) {
		 in.setNumParc(numParc.getInteger());
		 in.setEtat(etat.getValue());
	 }

	 public void setFieldValues(Materiel src) {
		 numParc.setInteger(src.getNumParc());
		 etat.setValue(src.getEtat());
	 }

}
